package com.team.recruitment_management_system.controller;

import com.team.recruitment_management_system.pojo.dto.resume.AddResumeDto;
import com.team.recruitment_management_system.pojo.entity.Resume;
import com.team.recruitment_management_system.service.ResumeService;
import com.team.recruitment_management_system.util.result.Result;
import com.team.recruitment_management_system.util.result.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * time 2024.3.27
 * author xxxty
 */
@RestController
@RequestMapping("/sys/resume")
@Tag(name = "简历模块")
public class ResumeController {
    @Autowired
    ResumeService resumeService;

    @PostMapping("/add")
    @Operation(summary = "新增简历",security = {@SecurityRequirement(name = "Authorization")})
    Result add(@RequestBody @Validated AddResumeDto resume){
        return resumeService.addOne(resume);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除简历")
    Result deleteById(@PathVariable Integer id){
       return resumeService.removeById(id) == false?Result.build("", ResultCodeEnum.ILLEGAL_OPERATION):Result.ok(null,"");
    }

    @GetMapping("/findById")
    @Operation(summary = "查找简历")
    Result findOne(@RequestHeader String authorization){
        return Result.ok(resumeService.FindOne(authorization));
    }

    @GetMapping("/findByResumeId/{id}")
    @Operation(summary = "通过简历id查找简历", security = {@SecurityRequirement(name = "Authorization")})
    Result findOneByResumeId(@PathVariable int id){
        return Result.ok(resumeService.getById(id));
    }

    @PostMapping("/update")
    @Operation(summary = "更新简历")
    Result upDate(@RequestBody Resume resume){
        return resumeService.updateById(resume) ?Result.ok(null,"修改成功"):Result.build(null, ResultCodeEnum.ILLEGAL_OPERATION);
    }
}
